package com.smap.proj;

import com.smap.core.Projection;
import com.smap.core.XY;

/**
 * used by most commercial map
 *
 * @author shen
 *
 */
public class SphericalMercator implements Projection {
	public static final double EQUATORIALRADIUS = 6378137.0;

	public double getMaxResolution() {
		return 2 * Math.PI * EQUATORIALRADIUS / 256;
	}

	public String getSRS() {
		return "EPSG:900913";
	}

	public void project(XY coord) {
		coord.y = EQUATORIALRADIUS
				* (Math.log(Math.tan(Math.PI / 4 + Math.toRadians(coord.y) / 2)));
		coord.x = EQUATORIALRADIUS * Math.toRadians(coord.x);
	}

	public void reversProject(XY coord) {
		coord.x = Math.toDegrees(coord.x / EQUATORIALRADIUS);
		coord.y = Math.toDegrees(Math.atan(Math
				.sinh(coord.y / EQUATORIALRADIUS)));
	}


}
